home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / SCHEME / GNU / SCM4E1 / !Scm / slib / repl < prev    next >
Text File  |  1993-04-02  |  2KB  |  70 lines

  1. ; "repl.scm", read-eval-print-loop for Scheme
  2. ; Copyright (c) 1993, Aubrey Jaffer
  3.  
  4. ;Permission to copy this software, to redistribute it, and to use it
  5. ;for any purpose is granted, subject to the following restrictions and
  6. ;understandings.
  7.  
  8. ;1.  Any copy made of this software must include this copyright notice
  9. ;in full.
  10.  
  11. ;2.  I have made no warrantee or representation that the operation of
  12. ;this software will be error-free, and I am under no obligation to
  13. ;provide any services, by way of maintenance, update, or otherwise.
  14.  
  15. ;3.  In conjunction with products arising from the use of this
  16. ;material, there shall be no use of my name in any advertising,
  17. ;promotional, or sales literature without prior written consent in
  18. ;each case.
  19.  
  20. (require 'dynamic-wind)
  21. (define (repl:quit) (slib:error "not in repl:repl"))
  22.  
  23. (define (repl:top-level repl:eval)
  24.   (repl:repl (lambda () (display "> ")
  25.              (force-output (current-output-port))
  26.              (read))
  27.          repl:eval
  28.          (lambda (obj) (write obj) (newline))))
  29.  
  30. (define (repl:repl repl:read repl:eval repl:print)
  31.   (let* ((old-quit repl:quit)
  32.      (old-error slib:error)
  33.      (old-eval slib:eval)
  34.      (old-load load)
  35.      (repl:load (lambda (<pathname>)
  36.               (call-with-input-file <pathname>
  37.             (lambda (port)
  38.               (let ((old-load-pathname *load-pathname*))
  39.                 (set! *load-pathname* <pathname>)
  40.                 (do ((o (read port) (read port)))
  41.                 ((eof-object? o))
  42.                   (repl:eval o))
  43.                 (set! *load-pathname* old-load-pathname))))))
  44.      (repl:restart #f)
  45.      (repl:error (lambda args (require 'debug) (apply qpn args)
  46.                  (repl:restart #f))))
  47.     (dynamic-wind
  48.      (lambda ()
  49.        (set! load repl:load)
  50.        (set! slib:eval repl:eval)
  51.        (set! slib:error repl:error)
  52.        (set! repl:quit
  53.          (lambda () (let ((cont repl:restart))
  54.               (set! repl:restart #f)
  55.               (cont #t)))))
  56.      (lambda ()
  57.        (do () ((call-with-current-continuation
  58.         (lambda (cont)
  59.           (set! repl:restart cont)
  60.           (do ((obj (repl:read) (repl:read)))
  61.               ((eof-object? obj) (repl:quit))
  62.             (repl:print (repl:eval obj))))))))
  63.      (lambda () (cond (repl:restart
  64.                (display ">>ERROR<<") (newline)
  65.                (repl:restart #f)))
  66.          (set! load old-load)
  67.          (set! slib:eval old-eval)
  68.          (set! slib:error old-error)
  69.          (set! repl:quit old-quit)))))
  70.